﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeepSpace.Geometry
{
    public class Vector
    {
        public double X { get; set; }
        public double Y { get; set; }
        public double Z { get; set; }

        public double Length
        {
            get
            {
                return Math.Sqrt(X * X + Y * Y + Z * Z);
            }
        }

        private bool isNormailized;

        public Vector(double x = 0, double y = 0, double z = 0, bool normalized = false)
        {
            X = x;
            Y = y;
            Z = z;
            this.isNormailized = normalized;
        }

        public double Dot(Vector other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            return X * other.X + Y * other.Y + Z * other.Z;
        }

        public Vector Normailize()
        {
            if (isNormailized)
            {
                return this;
            }

            double rlength = 1.0 / Length;

            return new Vector(X * rlength, Y * rlength, Z * rlength, true);
        }
    }
}
